home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
OLE2BOOK.ZIP
/
CHAP12.ZIP
/
PATRON
/
PAGE.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-27
|
29KB
|
1,174 lines
/*
* PAGE.CPP
* Modifications for Chapter 12
*
* Implementation of parts of the CPage class; those member functions
* dealing with mouse events are in PAGEMOUS.CPP
*
* Copyright (c)1993 Microsoft Corporation, All Rights Reserved
*
* Kraig Brockschmidt, Software Design Engineer
* Microsoft Systems Developer Relations
*
* Internet : kraigb@microsoft.com
* Compuserve: >INTERNET:kraigb@microsoft.com
*/
#include "patron.h"
/*
* CPage::CPage
* CPage::~CPage
*
* Constructor Parameters:
* dwID DWORD identifier for this page.
* hWnd HWND of the pages window (for repaints, etc).
* pPG LPCPages to the Pages window.
*/
CPage::CPage(DWORD dwID, HWND hWnd, LPCPages pPG)
{
m_dwID =dwID;
m_pIStorage=NULL;
m_cOpens=0;
m_hWnd=hWnd;
m_pPG=pPG;
m_dwIDNext =0;
m_cTenants =0;
m_hWndTenantList=NULL;
m_iTenantCur =0xFFFF; //Tenants are zero indexed.
m_pTenantCur =NULL;
m_uHTCode=HTNOWHERE;
m_uSizingFlags=0;
m_fTracking=FALSE;
m_hDC=NULL;
return;
}
CPage::~CPage(void)
{
m_hWnd=NULL;
Close(FALSE);
return;
}
/*
* CPage::GetID
*
* Return Value:
* DWORD dwID field in this page. This function is only here
* to avoid hiding inline implementations in pages.h
*/
DWORD CPage::GetID(void)
{
return m_dwID;
}
/*
* CPage::FOpen
*
* Purpose:
* Retrieves the IStorage associated with this page. The IStorage is
* owned by the page and thus the page always holds a reference count.
* The caller should call ::Close or delete this page to match this open.
*
* This function may be called multiple times resulting in additional
* reference counts on the storage each of which must be matched with
* a call to ::Close. The last ::Close can be done through delete.
*
* Parameters:
* pIStorage LPSTORAGE in which this page lives.
*
* Return Value:
* BOOL TRUE if opening succeeds, FALSE otherwise.
*/
BOOL CPage::FOpen(LPSTORAGE pIStorage)
{
HRESULT hr=NOERROR;
LPSTREAM pIStream;
DWORD dwMode;
char szTemp[32];
BOOL fNew;
BOOL fCreated=FALSE;
TENANTLIST tl;
LPTENANTINFO pti;
ULONG cb;
LPMALLOC pIMalloc;
UINT i;
LPTENANT pTenant;
//CHAPTER12MOD
UINT cLinks;
LPOLELINK pIOleLink;
LPUNKNOWN pIUnknown;
UINT uRet;
OLEUIEDITLINKS el;
LPCIOleUILinkContainer pIUILinks;
HWND hWndDoc;
//End CHAPTER12MOD
fNew=(NULL==m_pIStorage);
if (!fNew)
{
m_cOpens++;
m_pIStorage->AddRef();
return TRUE;
}
if (NULL==pIStorage)
return FALSE;
/*
* Attempt to open the storage under this ID. If there is none, then
* create it. In either case we end up with an IStorage that we
* either save in pPage or release.
*/
GetStorageName(szTemp);
dwMode=STGM_TRANSACTED | STGM_READWRITE | STGM_SHARE_EXCLUSIVE;
hr=pIStorage->OpenStorage(szTemp, NULL, dwMode, NULL, 0, &m_pIStorage);
if (FAILED(hr))
{
hr=pIStorage->CreateStorage(szTemp, dwMode, 0, 0, &m_pIStorage);
fCreated=TRUE;
}
if (FAILED(hr))
return FALSE;
m_cOpens++;
if (NULL==m_hWndTenantList)
{
/*
* The first time we open this page, create the hidden listbox
* we'll use to track tenants. We give it the owner-draw style
* so we can just store pointers in it.
*/
m_hWndTenantList=CreateWindow("listbox", "Tenant List"
, WS_POPUP | LBS_OWNERDRAWFIXED, 0, 0, 100, 100
, HWND_DESKTOP, NULL, m_pPG->m_hInst, NULL);
if (NULL==m_hWndTenantList)
return FALSE;
}
//If this is brand-new, we're done.
if (fCreated)
return TRUE;
/*
* Now open the stream we saved in ::Close and load all the
* tenants listed in there. If there are none, then we don't
* have to load squat.
*/
hr=m_pIStorage->OpenStream(SZSTREAMTENANTLIST, NULL, STGM_DIRECT
| STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &pIStream);
if (FAILED(hr))
return FALSE;
if (SUCCEEDED(CoGetMalloc(MEMCTX_SHARED, &pIMalloc)))
{
pIStream->Read((LPVOID)&tl, sizeof(tl), NULL);
m_cTenants=tl.cTenants;
m_dwIDNext=tl.dwIDNext;
m_iTenantCur=0;
cb=tl.cTenants*sizeof(TENANTINFO);
if (0!=cb)
{
pti=(LPTENANTINFO)pIMalloc->Alloc(cb);
if (NULL!=pti)
{
pIStream->Read((LPVOID)pti, cb, NULL);
for (i=0; i < m_cTenants; i++)
{
if (FTenantAdd(-1, (pti+i)->dwID, &pTenant))
{
pTenant->FLoad(m_pIStorage, &(pti+i)->fe, &(pti+i)->rcl);
//CHAPTER12MOD
//Make sure it knows about the show state.
pTenant->ShowObjectType(m_pPG->m_fShowTypes);
//End CHAPTER12MOD
}
}
pIMalloc->Free((LPVOID)pti);
}
}
pIMalloc->Release();
}
pIStream->Release();
//Get and select the first tenant
if (FTenantGet(0, &m_pTenantCur, FALSE))
m_pTenantCur->Select(TRUE);
//CHAPTER12MOD
/*
* Update all the links in this page, showing the progress indicator
* as it's happening. We use the same IOlUILinkContainer
* implementation as we do for the links dialog, passing it to
* OleUIUpdateLinks which does everything for us.
*
* We might also optimize this to not do anything if there are no
* automatic links, but it's not a big concern.
*/
//First, count the number of automatic links.
cLinks=0;
for (i=0; i < m_cTenants; i++)
{
if (FTenantGet(i, &pTenant, FALSE))
{
DWORD dw;
pTenant->ObjectGet(&pIUnknown);
hr=pIUnknown->QueryInterface(IID_IOleLink, (LPLPVOID)&pIOleLink);
pIUnknown->Release();
if (FAILED(hr))
continue;
pIOleLink->GetUpdateOptions(&dw);
pIOleLink->Release();
if (OLEUPDATE_ALWAYS==dw)
cLinks++;
}
}
//If we have any automatic links, invoke the update dialog.
if (0==cLinks)
return TRUE;
//Create an IOleUILinkContainer instantiation.
if (!m_pPG->FGetUILinkContainer(&pIUILinks))
return TRUE; //Guess we can't update, oh well.
hWndDoc=GetParent(m_hWnd);
LoadString(m_pPG->m_hInst, IDS_CAPTION, szTemp, sizeof(szTemp));
if (!OleUIUpdateLinks(pIUILinks, hWndDoc, szTemp, cLinks))
{
/*
* If updating failed, ask to show the links dialog. NOTE:
* OleUIPromptUser has a variable wsprintf type argument list
* after the hWnd parameter! Use appropriate typecasting!
*/
uRet=OleUIPromptUser(IDD_CANNOTUPDATELINK, hWndDoc, (LPSTR)szTemp);
if (ID_PU_LINKS==uRet)
{
//Throw up the links dialog.
_fmemset(&el, 0, sizeof(el));
el.cbStruct=sizeof(el);
el.hWndOwner=hWndDoc;
el.lpOleUILinkContainer=(LPOLEUILINKCONTAINER)pIUILinks;
OleUIEditLinks((LPOLEUIEDITLINKS)&el);
}
}
m_pPG->m_fDirty=pIUILinks->m_fDirty;
pIUILi